<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['hdps']=$basic['hdps'];
if($_RQ['op']=='main'){	
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	set_html('title','门店列表');
	$return['sharedata']=array(
		'title'=>'门店列表'.$basic['share_title'],
		'desc'=>'门店列表'.$basic['share_desc'],
		'link'=>custom_url('jy_bdd/store_list/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	//排序门店
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if(!empty($post['province'])){
		$params['province']=$post['province'];
		$return['params']['province']=$post['params']['province'];
	}
	if(!empty($post['city'])){
		$params['city']=$post['city'];
		$return['params']['city']=$post['params']['city'];
	}
	
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	//$list=pdo_getslice('jy_bdd_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$return['status']=0;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=$this->model('model')->get($parameter,$total,$post['lat_lng']);
	$sum=0;
	if($list){
		$sum=count($list);
		foreach($list as &$item){		
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	if($post['keyword']=='zhonghe'){
		paixu($list,'id','desc');
	}else{
		paixu($list,'juli','asc');
	}
	$return['list']=$list;
	$return['sum']=$sum;
	set_html('title','门店列表');
	$return['sharedata']=array(
		'title'=>'门店列表'.$basic['share_title'],
		'desc'=>'门店列表'.$basic['share_desc'],
		'link'=>custom_url('jy_bdd/store_list/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='o_detail'){
	if(!$_RQ['id']){
		exi('没有找到该门店，请重新选择！','error');
	}
	$opus=pdo_get('jy_bdd_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//进入门店详情，记录访问者浏览信息
	$islook=pdo_get('jy_bdd_looklist',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(empty($islook)){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'oid'=>$_RQ['id'],
			'mid'=>$_SESSION['uid'],
			'createtime'=>TIMESTAMP
		
		);
		pdo_insert('jy_bdd_looklist',$insert);
	}
	$opus['createtime']=date('Y-m-d H:i:s',$opus['createtime']);
	$return['opus']=$opus;
	exi($return);
}
if($_RQ['op']=='like'){
	
	if(!$_RQ['id']){
		exi('没有找到该门店，请重新选择！','error');
	}
	$like=$_RQ['like'];
	$opus=pdo_get('jy_bdd_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	if($like==1){
		pdo_update('jy_bdd_opus',array('like'=>$opus['like']+1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		pdo_update('jy_bdd_looklist',array('islike'=>1),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
		
	}else{
		pdo_update('jy_bdd_opus',array('like'=>$opus['like']-1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		pdo_update('jy_bdd_looklist',array('islike'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	

}	
